using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.TextEditor.Gui.CompletionWindow;

namespace ICSharpCode.TextEditor.Formatting.Intellisense
{
    public class JsonCompletionDataSupplier : ICompletionDataSupplier
    {
        private string HandleKeyWord(string lineText, char charTyped)
        {
            string empty = string.Empty;
            List<char> list = new List<char>();
            char[] array = (lineText + charTyped).ToCharArray();
            int num = array.Length - 1;
            while (num >= 0 && array[num] != ' ' && array[num] != '"' && array[num] != '(' && array[num] != '>')
            {
                list.Add(array[num]);
                if (array[num] == ':')
                {
                    break;
                }
                num--;
            }
            list.Reverse();
            return string.Join("", list.ToArray()).Trim();
        }

        public ICompletionData[] GetCompletionData(string lastkeyword, char charTyped)
        {
            ICompletionData[] source = new ICompletionData[6]
            {
                new StringCompletionData("ConnectionStrings", "", 1),
                new StringCompletionData("Development", "", 1),
                new StringCompletionData("IncludeScopes", "", 1),
                new StringCompletionData("Logging", "", 1),
                new StringCompletionData("true", "Boolean", 1),
                new StringCompletionData("false", "Boolean", 1)
            };
            string keyword = HandleKeyWord(lastkeyword, charTyped);
            if (keyword.StartsWith(":"))
            {
                keyword = keyword.Substring(1);
                if (!string.IsNullOrEmpty(keyword) && keyword.Length > 1)
                {
                    IEnumerable<ICompletionData> enumerable = source.Where((ICompletionData w) => w.Text.StartsWith(keyword, StringComparison.OrdinalIgnoreCase));
                    if (enumerable != null && enumerable.Count() > 0)
                    {
                        return enumerable.ToArray();
                    }
                }
            }
            else if (!string.IsNullOrEmpty(keyword) && keyword.Length > 1)
            {
                IEnumerable<ICompletionData> enumerable2 = source.Where((ICompletionData w) => w.Text.StartsWith(keyword, StringComparison.OrdinalIgnoreCase));
                if (enumerable2 != null && enumerable2.Count() > 0)
                {
                    return enumerable2.ToArray();
                }
            }
            return null;
        }
    }
}
